﻿
using iss.sg4210.se18.team6s.jass.DAL.DataAccess.Interfaces;
using System.Linq;

namespace iss.sg4210.se18.team6s.jass.DAL.DataAccess.MSSQL
{
    public class GeographicalAreaDAO : ObjectDAO, IGeographicalArea
    {

        public GeographicalAreaDAO()
            : base() { }

        public IQueryable<GeoArea> FindAllGeographicalAreas()
        {
            return jassEntities.GeoAreas;
        }

        public GeoArea GetGeographicalArea(int geographicalAreaId)
        {
            return jassEntities.GeoAreas.SingleOrDefault<GeoArea>(m => m.Id == geographicalAreaId);
        }

        public void AddGeographicalArea(GeoArea geographicalArea)
        {
            jassEntities.AddToGeoAreas(geographicalArea);
            Save();
        }

        public void UpdateGeographicalArea(GeoArea geographicalArea)
        {
            jassEntities.GeoAreas.ApplyCurrentValues(geographicalArea);
            Save();
        }

        public void DeleteGeographicalArea(int geographicalAreaId)
        {
            GeoArea geoArea = GetGeographicalArea(geographicalAreaId);
            jassEntities.GeoAreas.DeleteObject(geoArea);
            Save();
        }
    }
}
